﻿//----------------------------------------------------------------------------------------------------------------------
// <copyright file="PomodoroCalendarControl.xaml.cs" company="Keith B. Rimington">
//
//   Copyright (c) 2011 Keith B. Rimington
//
//   Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
//     documentation files (the "Software"), to deal in the Software without restriction, including without limitation
//     the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
//     to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
//   The above copyright notice and this permission notice shall be included in all copies or substantial portions of
//     the Software.
//
//   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//     THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
//     CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
//     DEALINGS IN THE SOFTWARE.
//
// </copyright>
//----------------------------------------------------------------------------------------------------------------------

namespace Noc.Pomodoro.Controls
{
    using System;
    using System.Windows;
    using System.Windows.Controls;

    /// <summary>
    /// Interaction logic for PomodoroCalendarControl.xaml
    /// </summary>
    public partial class PomodoroCalendarControl : UserControl
    {
        /// <summary>
        /// Backing store for the SelectedDate property.
        /// </summary>
        public static readonly DependencyProperty SelectedDateProperty = DependencyProperty.Register("SelectedDate", typeof(DateTime), typeof(PomodoroCalendarControl), new PropertyMetadata(DateTime.Today));

        /// <summary>
        /// Initializes a new instance of the <see cref="PomodoroCalendarControl"/> class.
        /// </summary>
        public PomodoroCalendarControl()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Gets or sets the current selected date.
        /// </summary>
        /// <value>
        /// The selected date.
        /// </value>
        public DateTime SelectedDate
        {
            get { return (DateTime)GetValue(SelectedDateProperty); }
            set { SetValue(SelectedDateProperty, value.Date); }
        }

        /// <summary>
        /// Called when the previous button is clicked, to advance the selection to the previous day.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void OnPreviousButtonClicked(object sender, RoutedEventArgs e)
        {
            this.SelectedDate = this.SelectedDate.AddDays(-1);
        }

        /// <summary>
        /// Called when next button is clicked, to advance the selection to the next day.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void OnNextButtonClicked(object sender, RoutedEventArgs e)
        {
            this.SelectedDate = this.SelectedDate.AddDays(1);
        }

        /// <summary>
        /// Called when the calendar selection changes, to ensure that the popup closes.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Controls.SelectionChangedEventArgs"/> instance containing the event data.</param>
        private void OnCalendarSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this.popupCalendar.IsOpen = false;
        }
    }
}